package com.book.controller;

import com.book.pojo.Address;
import com.book.pojo.User;
import com.book.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    @PostMapping("/save")
    @ResponseBody
    public String save(Address address, HttpSession session){
        User user = (User)session.getAttribute("user");
        address.setUserId(user.getId());
        addressService.save(address); //保存收货地址
        return "success";
    }
}
